<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('任务管理列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>优先级：</label>
                            <select name="priority" class="form-control m-b"
                                    th:with="type=${@dict.getType('task_priority')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
<!--                        <li>-->
<!--                            <label>任务类型：</label>-->
<!--                            <select name="type" class="form-control m-b"-->
<!--                                    th:with="type=${@dict.getType('okr_task_type')}">-->
<!--                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
<!--                            </select>-->
<!--                        </li>-->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:task:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:task:remove')}]];
    var prefix = ctx + "system/task";

    var tasks = [[${tasks}]]
    var taskIds = []

    $(function() {
        for (let i = 0; i < tasks.length; i++) {
            taskIds[i] = tasks[i].id
        }
        var options = {
            url: prefix + "/list",
            modalName: "任务管理",
            columns: [{
                checkbox: true,
                formatter: function(value, row, index){
                    if (taskIds.includes(row.id)){
                        return { checked : true };
                    }else{
                        return { checked : false };
                    }
                }
            },
                {
                    field: 'id',
                    visible: false
                },
                {
                    field: 'taskName',
                    title: '任务'
                },
                {
                    field: 'beginTime',
                    title: '开始时间'
                },
                {
                    field: 'endTime',
                    title: '结束时间'
                },
                {
                    field: 'priority',
                    title: '优先级'
                },
                {
                    field: 'type',
                    title: '类型'
                }
                ]
        };
        $.table.init(options);
    });


    function submitHandler(){
        var selectRows = $.table.selectRowData();
        var taskIds = new Array()
        if (selectRows.length > 0){
            for (var i = 0; i < selectRows.length; i++) {
                taskIds.push(selectRows[i].id)
            }
        }else{
            taskIds.push(-1);
        }
        $.ajax({
            url:ctx + 'system/task/linkOkrWithTask',
            data: {'taskIds' : taskIds},
            type: 'POST',
            success: function(data){
                $.modal.msgReload(data.msg, modal_status.SUCCESS)
            }
        })
        $.modal.close();
    }
</script>
</body>
</html>